/**
 * Copyright (C)  2011  chen wei hua.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 2.0
 * or any later version published by the Free Software Foundation;
 * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 * A copy of the license is included in the section entitled "GNU Free Documentation License".
 */
package com.javaeye.common.service;

import java.util.List;

import com.javaeye.common.dao.ModuleDAO;
import com.javaeye.common.dto.Module;

public class ModuleService implements IModuleService {
	
	private ModuleDAO moduleDao;
	
	public void setModuleDao(ModuleDAO moduleDao) {
		this.moduleDao = moduleDao;
	}

	public List<Module> getModules() {
		List<Module> result = moduleDao.getModules();
		return result;
	}
	
	public Module getModule(int moduleId) {
		Module module = moduleDao.getModule(moduleId);
		return module;
	}
	
	public List<Module> getModules(int parentId) {
		List<Module> result = moduleDao.getModules(parentId);
		if (parentId > 0) {
			Module root = moduleDao.getModule(parentId);
			result.add(0, root);
		}
		return result;
	}
	
}
